package kd.bos.demo_plugin.baseinfo;

import java.util.ArrayList;
import java.util.EventObject;

import antlr.StringUtils;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.control.events.BeforeItemClickEvent;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.list.IListView;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.epm.eb.formplugin.AbstractListPlugin;

public class changeStatus extends AbstractListPlugin{
    private final static String KEY_MAINBAR = "tbmain";
	private final static String KEY_BARITEM_NEW = "comt_baritemap";
	
	@Override
	public void registerListener(EventObject e) {
		super.registerListener(e);
		// 侦听主菜单按钮点击事件
		this.addItemClickListeners(KEY_MAINBAR);//自定义按钮的标识
	}

	@Override
	public void itemClick(ItemClickEvent evt) {
		super.itemClick(evt);
        if(KEY_BARITEM_NEW.equals(evt.getItemKey())){
            this.getView().showSuccessNotification("arg0");
            //获取用户选中的行
            IListView view = (IListView)this.getView();//获取列表实例
            //IListView v = (IListView)getView();
            ListSelectedRowCollection selectRows = view.getSelectedRows();//获取选中行
            if(selectRows.size()==0){//选择的为空
                this.getView().showErrorNotification("请选择书籍");
                return;
            }
            String billFormId = view.getBillFormId();//获取列表绑定的单据 就是列表标识
            Object[] pkArr = selectRows.getPrimaryKeyValues();
            QFilter idQFilter = new QFilter("id",QCP.in,pkArr);
            DynamicObject[] load = BusinessDataServiceHelper.load(billFormId, "comt_basedatafield.comt_book_status1",new QFilter[]{idQFilter});
            
            for(DynamicObject ob : load){
                ob.set("comt_basedatafield.comt_book_status1","下架");
            }

            SaveServiceHelper.update(load);
            //this.getView().invokeOperation("refresh");
            this.getView().updateView();
        }
	}



}
